"""Add stock column to Details table

Revision ID: d9983e819268
Revises:
Create Date: 2025-06-25 10:45:45.149298

"""

from alembic import op
import sqlalchemy as sa
from sqlalchemy import inspect


# revision identifiers, used by Alembic.
revision = "d9983e819268"
down_revision = None
branch_labels = None
depends_on = None


def column_exists(table_name, column_name):
    conn = op.get_bind()
    inspector = inspect(conn)
    columns = [col["name"] for col in inspector.get_columns(table_name)]
    return column_name in columns


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table("details", schema=None) as batch_op:
        if not column_exists("details", "stock"):
            batch_op.add_column(sa.Column("stock", sa.NUMERIC(10, 3), nullable=True))

    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table("details", schema=None) as batch_op:
        batch_op.drop_column("stock")

    # ### end Alembic commands ###
